package com.ruoyi.web.controller;

import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.web.entity.CustomerCoupons;
import com.ruoyi.web.service.ICustomerCouponsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lqc
 * @since 2024-01-29
 */
@RestController
@RequestMapping("/admin/customer-coupons")
public class CustomerCouponsController extends BaseController {

    private final ICustomerCouponsService customerCouponsServiceImpl;

    public CustomerCouponsController(ICustomerCouponsService customerCouponsServiceImpl) {
        this.customerCouponsServiceImpl = customerCouponsServiceImpl;
    }

    @GetMapping("/getCoupon/{id}")
    public AjaxResult getCoupon(@PathVariable("id") Long id) {
        LoginUser loginUser = getLoginUser();
        Long userId = loginUser.getUserId();
        CustomerCoupons customerCoupons = new CustomerCoupons();
        customerCoupons.setId(IdUtil.getSnowflakeNextId());
        customerCoupons.setCouponId(id);
        customerCoupons.setCustomId(userId);
        customerCoupons.setStatus(0);
        customerCouponsServiceImpl.save(customerCoupons);
        return success();
    }

}
